package com.rcm.dda.validator;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.rcm.dda.exception.DDAValidationException;

public class ValidatorUnit implements Serializable {

	private static final long serialVersionUID = -4981725811851944658L;

	private Map<String, ErrorEnum> errors;

	private ValidatorUnit() {
	}
	
	public static ValidatorUnit createInstance() {
		return new ValidatorUnit();
	}

	public void add(String field, ErrorEnum enu) {
		if (errors == null) {
			errors = new HashMap<String, ErrorEnum>();
		}
		errors.put(field, enu);
	}

	public boolean isEmpty() {
		return errors == null || errors.isEmpty();
	}

	public Map<String, ErrorEnum> getErrors() {
		return errors;
	}
	
	public void end() throws DDAValidationException {
		if (!isEmpty()) {
			throw new DDAValidationException(this);
		}
	}

}
